﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for CommonMethods
/// </summary>
public  class CommonMethods
{
    public System.Object getAllCompanies()
    {
        using (POSEntities db = new POSEntities())
        {
            var companies = (from c in db.Companies
                             join cit in db.Cities on c.City equals cit.City_ID
                             select new { c.CompanyId, c.CompanyName, c.Phone, c.City, c.Address, cit.City_Name }).ToList();

            return companies;

        }
    }
    public System.Object getBranchesWithCompanyId(int CompanyId)
    {
        using (POSEntities db = new POSEntities())
        {
            var companies = (from b in db.Branches
                             join cit in db.Cities on b.City_ID equals cit.City_ID
                             join c in db.Companies on b.CompanyId equals c.CompanyId
                             where (b.CompanyId==CompanyId || CompanyId==0) && b.IsDeleted==false
                             select new {c.CompanyId, c.CompanyName,cit.City_ID, cit.City_Name,b.BranchId,b.BranchName }).ToList();

            return companies;

        }
    }
    public System.Object getDepartmentWithBranchId(int branchId)
    {
        using (POSEntities db = new POSEntities())
        {
            var departments = (from d in db.Departments
                             join b in db.Branches on d.BranchId equals b.BranchId
                             join c in db.Companies on b.CompanyId equals c.CompanyId
                             where (b.BranchId == branchId || branchId == 0) && d.Is_Deleted == false
                             select new { c.CompanyId, c.CompanyName,  b.BranchId, b.BranchName,d.Dept_ID,d.Dept_Name }).ToList();

            return departments;

        }
    }
    public System.Object getSubDepartmentWithDepartmentId(int DeptId)
    {
        using (POSEntities db = new POSEntities())
        {
            var subdepartments = (from sd in db.SubDepartments
                                  join d in db.Departments on sd.Dept_ID equals d.Dept_ID
                                  join b in db.Branches on d.BranchId equals b.BranchId
                                  join c in db.Companies on b.CompanyId equals c.CompanyId
                                  where (d.Dept_ID == DeptId) && d.Is_Deleted == false
                                  select new { c.CompanyId, c.CompanyName, b.BranchId, b.BranchName, d.Dept_ID, d.Dept_Name, sd.SubDeptID, sd.SubDeptName }).ToList();

            return subdepartments;

        }
    }
    public System.Object getCategory(int CompanyId)
    {
        using (POSEntities db = new POSEntities())
        {
            var Category = (from c in db.ItemCategories where c.CompanyId == CompanyId select c).ToList();                            
            return Category;

        }
    }

    public System.Object getSubCategory(int category)
    {
        using (POSEntities db = new POSEntities())
        {
            var subcategory = (from c in db.ItemSubCategories where c.CategoryId == category select c).ToList();
            return subcategory;

        }
    }
    public System.Object getManufacturer()
    {
        using (POSEntities db = new POSEntities())
        {
            var manufacturer = (from c in db.ItemManufacturers select c).ToList();
            return manufacturer;

        }
    }


}